home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WINSRC20.ZIP / DIALOG.C < prev    next >
C/C++ Source or Header  |  1990-10-20  |  14KB  |  428 lines

  1. /*
  2.  
  3.     various dialog-box code - there's more in DIALOG2.C
  4.  
  5. */
  6.  
  7. #include "windows.h"
  8. #include "winfract.h"
  9. #include "fractint.h"
  10. #include <string.h>
  11. #include <math.h>
  12. #include <stdio.h>
  13. #include <sys\types.h>
  14. #include <sys\stat.h>
  15.  
  16. extern HWND hwnd;                               /* handle to main window */
  17. extern char szHelpFileName[];                   /* Help file name*/
  18.  
  19. char DialogTitle[128];
  20. char FileName[128];
  21. char PathName[128];
  22. char OpenName[128];
  23. char DefPath[128];
  24. char DefSpec[13];
  25. char DefExt[10];
  26. char str[255];
  27.  
  28. OFSTRUCT OfStruct;                        /* information from OpenFile()     */
  29. struct stat FileStatus;                   /* information from fstat()      */
  30.  
  31.  
  32. /****************************************************************************
  33.  
  34.     FUNCTION: SaveAsDlg(HWND, unsigned, WORD, LONG)
  35.  
  36.     PURPOSE: Allows user to change name to save file to
  37.  
  38.     COMMENTS:
  39.  
  40.         This will initialize the window class if it is the first time this
  41.         application is run.  It then creates the window, and processes the
  42.         message loop until a PostQuitMessage is received.  It exits the
  43.         application by returning the value passed by the PostQuitMessage.
  44.  
  45. ****************************************************************************/
  46.  
  47. BOOL bSaveEnabled = FALSE;
  48.  
  49. extern int time_to_save;
  50.  
  51. int FAR PASCAL SaveAsDlg(hDlg, message, wParam, lParam)
  52. HWND hDlg;
  53. unsigned message;
  54. WORD wParam;
  55. LONG lParam;
  56. {
  57.     char TempName[128];
  58.  
  59.     switch (message) {
  60.  
  61.          case WM_KEYDOWN:
  62.              switch (wParam) {
  63.                  case VK_F1:
  64.                  /* F1, shifted F1 bring up the Help Index */
  65.                      WinHelp(hwnd,szHelpFileName,HELP_INDEX,0L);
  66.                      break;
  67.                  }
  68.                
  69.         case WM_INITDIALOG:
  70.  
  71.             SetDlgItemText(hDlg, ID_FILETITLE, DialogTitle);
  72.  
  73.             /* If no filename is entered, don't allow the user to save to it */
  74.  
  75.             if (!FileName[0])
  76.                 bSaveEnabled = FALSE;
  77.             else {
  78.                 bSaveEnabled = TRUE;
  79.  
  80.                 /* Process the path to fit within the IDC_PATH field */
  81.  
  82.                 DlgDirList(hDlg, DefPath, NULL, IDC_PATH, 0x4010);
  83.  
  84.                 /* Send the current filename to the edit control */
  85.  
  86.                 SetDlgItemText(hDlg, IDC_EDIT, FileName);
  87.  
  88.                 /* Accept all characters in the edit control */
  89.  
  90.                 SendDlgItemMessage(hDlg, IDC_EDIT, EM_SETSEL, 0,
  91.                     MAKELONG(0, 0x7fff));
  92.             }
  93.  
  94.             /* Enable or disable the save control depending on whether the
  95.              * filename exists.
  96.              */
  97.  
  98.             EnableWindow(GetDlgItem(hDlg, IDOK), bSaveEnabled);
  99.  
  100.             /* Set the focus to the edit control within the dialog box */
  101.  
  102.             SetFocus(GetDlgItem(hDlg, IDC_EDIT));
  103.             return (FALSE);                 /* FALSE since Focus was changed */
  104.  
  105.         case WM_COMMAND:
  106.             switch (wParam) {
  107.                 case IDC_EDIT:
  108.  
  109.                     /* If there was previously no filename in the edit
  110.                      * control, then the save control must be enabled as soon as
  111.                      * a character is entered.
  112.                      */
  113.  
  114.                     if (HIWORD(lParam) == EN_CHANGE && !bSaveEnabled)
  115.                     EnableWindow(GetDlgItem(hDlg, IDOK), bSaveEnabled = TRUE);
  116.                     return (TRUE);
  117.  
  118.                 case IDOK:
  119.  
  120.                    /* Get the filename from the edit control */
  121.  
  122.                     GetDlgItemText(hDlg, IDC_EDIT, TempName, 128);
  123.  
  124.                     /* If there are no wildcards, then separate the name into
  125.                      * path and name.  If a path was specified, replace the
  126.                      * default path with the new path.
  127.                      */
  128.  
  129.                     if (CheckFileName(hDlg, FileName, TempName)) {
  130.                         SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec,
  131.                             (LPSTR) FileName);
  132.                         if (str[0])
  133.                             strcpy(DefPath, str);
  134.  
  135.                         /* Tell the caller a filename was selected */
  136.  
  137.                         EndDialog(hDlg, IDOK);
  138.                         time_to_save = 1;
  139.                     }
  140.                     return (TRUE);
  141.  
  142.                 case IDCANCEL:
  143.  
  144.                     /* Tell the caller the user canceled the SaveAs function */
  145.  
  146.                     EndDialog(hDlg, IDCANCEL);
  147.                     time_to_save = 1;
  148.                     return (FALSE);
  149.             }
  150.             break;
  151.  
  152.     }
  153.     return (FALSE);
  154. }
  155.  
  156. /****************************************************************************
  157.  
  158.     FUNCTION: OpenDlg(HWND, unsigned, WORD, LONG)
  159.  
  160.     PURPOSE: Let user select a file, and return.  Open code not provided.
  161.  
  162. ****************************************************************************/
  163.  
  164. HANDLE FAR PASCAL OpenDlg(hDlg, message, wParam, lParam)
  165. HWND hDlg;
  166. unsigned message;
  167. WORD wParam;
  168. LONG lParam;
  169. {
  170.     WORD index;
  171.     PSTR pTptr;
  172.     HANDLE hFile=1;     /* Temp value for return */
  173.  
  174.     switch (message) {
  175.  
  176.         case WM_KEYDOWN:
  177.             switch (wParam) {
  178.                 case VK_F1:
  179.                 /* F1, shifted F1 bring up the Help Index */
  180.                     WinHelp(hwnd,szHelpFileName,HELP_INDEX,0L);
  181.                     break;
  182.                 }
  183.  
  184.         case WM_COMMAND:
  185.             switch (wParam) {
  186.  
  187.                 case IDC_LISTBOX:
  188.                     switch (HIWORD(lParam)) {
  189.  
  190.                         case LBN_SELCHANGE:
  191.                             /* If item is a directory name, append "*.*" */
  192.                             if (DlgDirSelect(hDlg, str, IDC_LISTBOX)) 
  193.                                 strcat(str, DefSpec);
  194.  
  195.                             SetDlgItemText(hDlg, IDC_EDIT, str);
  196.                             SendDlgItemMessage(hDlg,
  197.                                 IDC_EDIT,
  198.                                 EM_SETSEL,
  199.                                 NULL,
  200.                                 MAKELONG(0, 0x7fff));
  201.                             break;
  202.  
  203.                         case LBN_DBLCLK:
  204.                             goto openfile;
  205.                     }
  206.                     return (TRUE);
  207.  
  208.                 case IDOK:
  209. openfile:
  210.                     GetDlgItemText(hDlg, IDC_EDIT, OpenName, 128);
  211.                     if (strchr(OpenName, '*') || strchr(OpenName, '?')) {
  212.                         SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec,
  213.                             (LPSTR) OpenName);
  214.                         if (str[0])
  215.                             strcpy(DefPath, str);
  216.                         ChangeDefExt(DefExt, DefSpec);
  217.                         UpdateListBox(hDlg);
  218.                         return (TRUE);
  219.                     }
  220.  
  221.                     if (!OpenName[0]) {
  222.                         MessageBox(hDlg, "No filename specified.",
  223.                             NULL, MB_OK | MB_ICONHAND);
  224.                         return (TRUE);
  225.                     }
  226.  
  227.                     AddExt(OpenName, DefExt);
  228.                     strcpy(FileName, OpenName);
  229.  
  230.                     /* The routine to open the file would go here, and the */
  231.                     /* file handle would be returned instead of NULL.           */
  232.                     EndDialog(hDlg, hFile);
  233.                     return (TRUE);
  234.  
  235.                 case IDCANCEL:
  236.                     EndDialog(hDlg, NULL);
  237.                     return (FALSE);
  238.             }
  239.             break;
  240.  
  241.         case WM_INITDIALOG:                        /* message: initialize    */
  242.             UpdateListBox(hDlg);
  243.             SetDlgItemText(hDlg, ID_FILETITLE, DialogTitle);
  244.             SetDlgItemText(hDlg, IDC_EDIT, DefSpec);
  245.             SendDlgItemMessage(hDlg,               /* dialog handle      */
  246.                 IDC_EDIT,                          /* where to send message  */
  247.                 EM_SETSEL,                         /* select characters      */
  248.                 NULL,